Keras 安装

配置说明

  • 操作系统 Windows 10(64 bit)
  • 显卡 Intel HD Graphics Family(无力吐槽)
  • Python版本 3.6.2
    (如果你用的是Anaconda,python版本不会是问题,可以重新创建一个environment,参见同时安装python2和python3

Keras官网 Keras
我会尽量按照官网的步骤进行安装。

安装引擎

有三种引擎可选择:TensorFlow, Theano, or CNTK。
这里对给出三者的安装过程:

TensorFlow

官网(貌似被墙?):TensorFlow
中文社区:TensorFlow中文社区
本来TensorFlow是不支持Windows,但是Google官方在11月29号的开发者博客中宣布新的版本(0.12)将 增加对Windows的支持,于是我们也可以在Windows下安装这个引擎了。

1
2
3
4
5
# GPU版本
pip install --upgrade tensorflow-gpu
# CPU版本
pip install --upgrade tensorflow

注意可能需要更新pip的版本
如果安装GPU版本,还需要安装 CUDA 和 cuDNN。这里我们只安装CPU版本。
一般来说,下载网速会比较慢,此时可以用国内镜像(详细用法见python使用国内镜像):

1
pip install -i http://mirrors.aliyun.com/pypi/simple/ tensorflow

等待安装完毕即可。

Theano

Theano
使用pip:

1
pip install theano

使用镜像:

1
pip install -i http://mirrors.aliyun.com/pypi/simple/ theano

等待安装完毕即可。

CNTK

CNTK
简单的说,使用pip安装即可:

1
pip install url

url 根据自己的Python版本以及需要GPU还是CPU-Only在官网上找到对应的,如下图:
cntk
对于我的机器来说就是:

1
pip install https://cntk.ai/PythonWheel/CPU-Only/cntk-2.2-cp36-cp36m-win_amd64.whl

安装完成后可以检查是否安装成功:

1
python -c "import cntk; print(cntk.__version__)"

安装 Keras

只需一条命令:

1
pip install keras

安装成功后可以跑一个小例子(使用的是TensorFlow)
addition_rnn(实现两个数相加)

最后

用官网的一段话来作为结束:
Why this name, Keras?

Keras (κέρας) means horn in Greek. It is a reference to a literary image from ancient Greek and Latin literature, first found in the Odyssey, where dream spirits (Oneiroi, singular Oneiros) are divided between those who deceive men with false visions, who arrive to Earth through a gate of ivory, and those who announce a future that will come to pass, who arrive through a gate of horn. It’s a play on the words κέρας (horn) / κραίνω (fulfill), and ἐλέφας (ivory) / ἐλεφαίρομαι (deceive).

Keras was initially developed as part of the research effort of project ONEIROS (Open-ended Neuro-Electronic Intelligent Robot Operating System).

“Oneiroi are beyond our unravelling —who can be sure what tale they tell? Not all that men look for comes to pass. Two gates there are that give passage to fleeting Oneiroi; one is made of horn, one of ivory. The Oneiroi that pass through sawn ivory are deceitful, bearing a message that will not be fulfilled; those that come out through polished horn have truth behind them, to be accomplished for men who see them.” Homer, Odyssey 19. 562 ff (Shewring translation).